﻿using System.Text.RegularExpressions;

namespace Zero.WebAPI.Framework.ConfigModel
{
    /// <summary>
    /// API访问白名单
    /// </summary>
    public class APIWhiteList
    {
        public List<string> FullPathList { get; set; }
        public List<string> RegPathList { get; set; }

        public bool Match(string path)
        {
            if (FullPathList != null && FullPathList.Count != 0 && FullPathList.Any(p => p.Equals(path)))
                return true;
            if (RegPathList != null && RegPathList.Count != 0)
            {
                foreach (var pattern in RegPathList)
                {
                    Regex regex = new Regex(pattern);
                    Match match = regex.Match(path);
                    if (match.Success)
                        return true;
                }
            }

            return false;
        }
    }
}
